package llvmir.value.instructions;

import llvmir.value.Value;
import llvmir.value.structure.BasicBlock;
import llvmir.value.structure.Instruction;

public class Br extends Instruction {
    // 两种使用方法，改变控制流
    public Br(BasicBlock bb1, BasicBlock bb2, Value cond, BasicBlock own) {
        super("Br", null, own);
        operands.add(bb1);
        operands.add(bb2);
        operands.add(cond);
    }

    public Br(BasicBlock bb, BasicBlock own) {
        super("Br", null, own);
        operands.add(bb);
    }

    @Override
    public String toString() {
        if (operands.size() == 1) {
            return "br label %" + operands.get(0).getName();
        } else {
            return "br i1 " + operands.get(2).getName() + ", label %" +
                    operands.get(0).getName() + ", label %" +
                    operands.get(1).getName();
        }
    }

}
